package utility

import (
	"github.com/gogf/gf/v2/net/ghttp"
)

// 响应结构体
type Response struct {
	Code    int         `json:"code"` // 0:成功，非0:错误
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

// 成功响应
func ResponseSuccess(r *ghttp.Request, data interface{}) {
	r.Response.WriteJson(Response{
		Code:    200,
		Message: "success",
		Data:    data,
	})
}

// 错误响应
func ResponseError(r *ghttp.Request, code int, message string) {
	r.Response.WriteJson(Response{
		Code:    code,
		Message: message,
		Data:    nil,
	})
}
